package com.jdew.thkj.fragment;

import android.app.Activity;
import android.app.Dialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSONObject;
import com.jdew.thkj.R;
import com.jdew.thkj.activity.EnlargePreviewActivity;
import com.jdew.thkj.activity.JDProductDetailActivity;
import com.jdew.thkj.activity.LoginActivity;
import com.jdew.thkj.activity.MainActivity;
import com.jdew.thkj.activity.PddDetailActivity;
import com.jdew.thkj.activity.SharePictureActivity;
import com.jdew.thkj.activity.TbProductDetailActivity;
import com.jdew.thkj.adapter.HuifenAdapter;
import com.jdew.thkj.base.BaseFragment;
import com.jdew.thkj.bean.HuiFenBean;
import com.jdew.thkj.bean.JDBean;
import com.jdew.thkj.bean.PddlinkBean;
import com.jdew.thkj.bean.TbDetailBean;
import com.jdew.thkj.dialog.CommonDialog;
import com.jdew.thkj.manager.AppConfig;
import com.jdew.thkj.manager.ShareManager;
import com.jdew.thkj.network.RetrofitManager;
import com.jdew.thkj.network.api.RequestApi;
import com.jdew.thkj.onitemInterface.OnCopyClickListener;
import com.jdew.thkj.onitemInterface.OnItemClickListener;
import com.jdew.thkj.onitemInterface.OnItemPictureClickSelectListener;
import com.jdew.thkj.onitemInterface.OnShareClickListener;
import com.jdew.thkj.utils.DeviceUtils;
import com.jdew.thkj.utils.MD5Utils;
import com.jdew.thkj.utils.RegexValidateUtils;
import com.jdew.thkj.utils.ToastUtils;
import com.jdew.thkj.wxapi.WechatShareManeger;
import com.scwang.smartrefresh.header.MaterialHeader;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.footer.BallPulseFooter;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class ProductAreaFragment extends BaseFragment implements View.OnClickListener {
    @Bind(R.id.recyclerview)
    RecyclerView recyclerview;
    @Bind(R.id.smartRefresh)
    SmartRefreshLayout smartRefreshLayout;
    @Bind(R.id.all)
    CheckBox all;
    @Bind(R.id.tb)
    CheckBox tb;
    @Bind(R.id.jd)
    CheckBox jd;
    @Bind(R.id.pdd)
    CheckBox pdd;
    @Bind(R.id.noresult)
    TextView noresult;
    @Bind(R.id.result_view)
    RelativeLayout resultView;
    private HuifenAdapter adapter;
    private List<HuiFenBean.DataBean> dataList = new ArrayList<>();
    private int page = 1;
    private String itemId;
    private List<String> list = new ArrayList<>();
    private Dialog mShareDialog;
    private ShareManager shareManager;
    private Bitmap shareBitmap;
    private ArrayList<String> shareList = new ArrayList<>();
    private int pos;
    private String resultString = "";
    private String tkl;
    private String wxurl;
    private ClipboardManager cm;
    private String countId;
    private WechatShareManeger mShareManager;
    private String styleFrom = "0";
    private String shopFrom = "0";

    @Override
    protected int getContentViewId() {
        return R.layout.huifen_cicle;
    }

    @Override
    protected void onCreateViewT() {
        mActivity = (MainActivity) getActivity();
        mShareManager = WechatShareManeger.getInstance(mActivity);
        cm = (ClipboardManager) mActivity.getApplicationContext().getSystemService(mActivity.CLIPBOARD_SERVICE);
        sp = mActivity.getSharedPreferences("user", Activity.MODE_PRIVATE);
        editor = sp.edit();
        adapter = new HuifenAdapter(mActivity, dataList, 2);
        setRcycleview(recyclerview, adapter);
        adapter.setOnItemPictureClickListener(new OnItemPictureClickSelectListener() {
            @Override
            public void onItemPictureClick(int itemPostion, int pos, String url, List<String> urlList, ImageView imageView) {
                list.clear();
                for (int i = 0; i < dataList.get(itemPostion).getPictureList().size(); i++) {
                    list.add(dataList.get(itemPostion).getPictureList().get(i).getPictureUrl());
                }
                Intent in = new Intent(getContext(), EnlargePreviewActivity.class);
                in.putStringArrayListExtra("imageList", (ArrayList<String>) list);
                in.putExtra("position", pos);
                getContext().startActivity(in);
            }
        });
        adapter.setOnShareClickListener(new OnShareClickListener() {
            @Override
            public void onItemClick(int position) {
                pos = position;
                countId = dataList.get(pos).getContentId();
                resultString = "";
                resultString = RegexValidateUtils.unicodeToString(dataList.get(pos).getContentText()).replace("\\n", "\n").replace("\\", "").replace("￥","").replace("$","").replace("(","").replace(")","");
                if (sp.getString("SpareTwo", "").equals("")) {
                    startActivity(new Intent(mActivity, LoginActivity.class));
                } else if (sp.getString("SpareTwo", "").equals("1")) {
                    ToastUtils.getInstance(mActivity).showMessage("升级后才可以分享哦!");
                } else {
                    ToastUtils.getInstance(mActivity).showMessage("文本复制成功");
                    GetAddShareCount(countId);
                    pasteToResult();
                    showDialog(pos);
                }
            }
        });
        adapter.setItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                if (!RegexValidateUtils.isFastClick()) {
                    return;
                }
                if (sp.getString("SpareTwo", "").equals("")) {
                    startActivity(new Intent(mActivity, LoginActivity.class));
                } else if (sp.getString("UserSjPhone", "").equals("") && (!sp.getString("SpareTwo", "").equals("1"))) {
                    toset("检测到您还没有绑定上级,请到我的页面绑定上级");
                } else {
                    itemId = dataList.get(position).getPictureList().get(0).getItemId();
                    if (dataList.get(position).getGoodsSource().equals("1")) {
                        toTBDetail(itemId);
                    } else if (dataList.get(position).getGoodsSource().equals("2")) {
                        toJDDetail(itemId);
                    } else if (dataList.get(position).getGoodsSource().equals("3")) {
                        toPDDDetail(itemId);
                    }
                }
            }
        });

        adapter.setOncopyClickListener(new OnCopyClickListener() {
            @Override
            public void onItemClick(int position) {
                itemId = dataList.get(position).getPictureList().get(0).getItemId();
                if (dataList.get(position).getGoodsSource().equals("1")) {
                    GetTBProductDetail();
                } else if (dataList.get(position).getGoodsSource().equals("2")) {
                    GetJDdetail();
                } else if (dataList.get(position).getGoodsSource().equals("3")) {
                    GetPDDdetail();
                }
            }
        });
        smartRefreshLayout.setRefreshHeader(new MaterialHeader(mActivity));
        smartRefreshLayout.setRefreshFooter(new BallPulseFooter(mActivity));
        smartRefreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
            @Override
            public void onLoadMore(RefreshLayout refreshLayout) {
                page++;
                GetCommunity();
                smartRefreshLayout.finishLoadMore();
            }

            @Override
            public void onRefresh(RefreshLayout refreshLayout) {
                page = 1;
                smartRefreshLayout.setEnableLoadMore(true);
                GetCommunity();
                smartRefreshLayout.finishRefresh();
            }
        });
        all.setOnClickListener(this);
        tb.setOnClickListener(this);
        jd.setOnClickListener(this);
        pdd.setOnClickListener(this);
    }

    @Override
    public void initData() {
        GetCommunity();
    }

    public void GetCommunity() {
        if (!DeviceUtils.isNetworkAvalible(mActivity)) {
            if (!mActivity.isFinishing()) {
                ToastUtils.getInstance(mActivity).showMessage("网络连接错误请检查");
            }
            return;
        }
        String timesamp = RegexValidateUtils.getTime13();
        String numsamp = RegexValidateUtils.getRandom10();
        HashMap map = new HashMap();
        map.put("pageIndex", page);
        map.put("communityType", 2);
        map.put("shopFrom", shopFrom);
        map.put("styleFrom", styleFrom);
        RetrofitManager.getInstance(AppConfig.BASE_URL).createReq(RequestApi.class).GetCommunity(map, RegexValidateUtils.getUniquePsuedoID(), timesamp, numsamp, MD5Utils.getMD5(RegexValidateUtils.ASCIISort(timesamp + numsamp + RegexValidateUtils.getUniquePsuedoID() + sp.getString("SignToken", "") + "pageIndex" + page + "communityType2" + "shopFrom" + shopFrom + "styleFrom" + styleFrom)).toUpperCase()).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<HuiFenBean>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
                smartRefreshLayout.finishRefresh(false);
                smartRefreshLayout.finishLoadMore(false);
            }

            @Override
            public void onNext(HuiFenBean bean) {
                smartRefreshLayout.finishRefresh();
                smartRefreshLayout.finishLoadMore();
                if (bean.getCode().equals("0")) {
                    if (page == 1) {
                        dataList.clear();
                    }
                    dataList.addAll(bean.getData());
                    if (dataList.size() == 0) {
                        resultView.setVisibility(View.VISIBLE);
                        noresult.setText("暂无数据！");
                    }else{
                        resultView.setVisibility(View.GONE);
                    }
                    if (bean.getData().size() < 10 && bean.getData().size() >= 0) {
                        smartRefreshLayout.setEnableLoadMore(false);
                    }
                    adapter.setDataList(dataList);
                }
            }
        });
    }

    public void toTBDetail(String itemId) {
        Bundle b = new Bundle();
        b.putSerializable("itemId", itemId);
        startActivity(TbProductDetailActivity.class, b);
    }

    public void toJDDetail(String itemId) {
        Bundle b = new Bundle();
        b.putSerializable("itemId", itemId);
        startActivity(JDProductDetailActivity.class, b);
    }

    public void toPDDDetail(String itemId) {
        Bundle b = new Bundle();
        b.putSerializable("itemId", itemId);
        startActivity(PddDetailActivity.class, b);
    }

    /**
     * 初始化分享弹出框
     */
    private void initShareDialog(final int position) {
        mShareDialog = new Dialog(mActivity, R.style.dialog_bottom_full);
        mShareDialog.setCanceledOnTouchOutside(true);
        mShareDialog.setCancelable(true);
        Window window = mShareDialog.getWindow();
        window.setGravity(Gravity.BOTTOM);
        window.setWindowAnimations(R.style.share_animation);
        View view = View.inflate(mActivity, R.layout.layout_share, null);
        view.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mShareDialog != null && mShareDialog.isShowing()) {
                    mShareDialog.dismiss();
                }
            }
        });
        view.findViewById(R.id.wx).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                shareList.clear();
                for (int i = 0; i < dataList.get(pos).getPictureList().size(); i++) {
                    shareList.add(dataList.get(pos).getPictureList().get(i).getPictureUrl());
                }
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        share(0, "", "wx");
                    }
                }, 100);
            }
        });
        view.findViewById(R.id.friend_cricle).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final String shareurl = dataList.get(pos).getPictureList().get(0).getPictureUrl();
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        if (!shareurl.equals("") && null != shareurl) {
                            shareBitmap = RegexValidateUtils.returnBitmap(shareurl);
                            mShareManager.sharePicture(1, shareBitmap);
                        }
                    }
                }).start();
            }
        });
        view.findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                shareList.clear();
                for (int i = 0; i < dataList.get(pos).getPictureList().size(); i++) {
                    shareList.add(dataList.get(pos).getPictureList().get(i).getPictureUrl());
                }
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        for (int i = 0; i < shareList.size(); i++) {
                            final String url = shareList.get(i);
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    if (!url.equals("") && null != url) {
                                        if (null != shareBitmap) {
                                            shareBitmap.recycle();
                                        }
                                        shareBitmap = RegexValidateUtils.returnBitmap(url);
                                        RegexValidateUtils.saveBmp2Gallery(mActivity,shareBitmap);
                                        mShareDialog.dismiss();
                                    }
                                }
                            }).start();
                        }
                    }
                }, 100);
                Toast.makeText(mActivity, "图片保存成功，请进入相册查看", Toast.LENGTH_SHORT).show();
            }
        });
        window.setContentView(view);
        window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);//设置横向全屏
    }

    /**
     * 显示分享弹出框
     */
    private void showDialog(int position) {
        if (mShareDialog == null) {
            initShareDialog(position);
        }
        mShareDialog.show();
    }

    private void share(int i, String s, String mType) {
        shareManager = new ShareManager(mActivity);
        shareManager.setShareImage(i, shareList, s, mType);
    }

    private void pasteToResult() {
        cm.setPrimaryClip(ClipData.newPlainText(null, ""));
        // 检查剪贴板是否有内容
        if (!cm.hasPrimaryClip()) {
        } else {
            ClipData clipData = cm.getPrimaryClip();
            int count = clipData.getItemCount();
            for (int i = 0; i < count; ++i) {
                ClipData.Item item = clipData.getItemAt(i);
                CharSequence str = item.coerceToText(mActivity);
                resultString += str;
            }

        }
        cm.setPrimaryClip(ClipData.newPlainText(null, resultString));
    }

    @Override
    public void onResume() {
        super.onResume();
        resultString = "";
    }

    public void GetTBProductDetail() {
        if (sp.getString("SpareTwo", "").equals("")) {
            startActivity(new Intent(mActivity, LoginActivity.class));
        } else if (sp.getString("UserSjPhone", "").equals("") && (!sp.getString("SpareTwo", "").equals("1"))) {
            toset("检测到您还没有绑定上级,请到我的页面绑定上级");
        } else if (sp.getString("SpareTwo", "").equals("1")) {
            ToastUtils.getInstance(mActivity).showMessage("升级后才可以复制哦!");
        } else {
            String timesamp = RegexValidateUtils.getTime13();
            String numsamp = RegexValidateUtils.getRandom10();
            HashMap<String, Object> map = new HashMap();
            map.put("Item_Id", itemId);
            map.put("UserPhone", sp.getString("userPhone", ""));
            RetrofitManager.getInstance(AppConfig.BASE_URL).createReq(RequestApi.class).GetTBItemConvert(map, RegexValidateUtils.getUniquePsuedoID(), timesamp, numsamp, MD5Utils.getMD5(RegexValidateUtils.ASCIISort(timesamp + numsamp + RegexValidateUtils.getUniquePsuedoID() + sp.getString("SignToken", "") + "Item_Id" + itemId + "UserPhone" + sp.getString("userPhone", ""))).toUpperCase()).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<TbDetailBean>() {
                @Override
                public void onCompleted() {
                }

                @Override
                public void onError(Throwable e) {
                }

                @Override
                public void onNext(TbDetailBean bean) {
                    if (bean.getCode().equals("0")) {
                        cm.setPrimaryClip(ClipData.newPlainText(null, ""));
                        wxurl = bean.getData().getWxUrl();
                        tkl = bean.getData().getTkl();
                        cm.setPrimaryClip(ClipData.newPlainText(null, "复制" + tkl + "到淘宝即可领券购买\n" + "领券链接\n" + wxurl));
                        ToastUtils.getInstance(mActivity).showMessage("口令复制成功");
                    } else if (bean.getCode().equals("-1")) {
                        commomDialog("该优惠券已被抢光");
                    }
                }
            });
        }
    }

    public void GetAddShareCount(String countId) {
        String timesamp = RegexValidateUtils.getTime13();
        String numsamp = RegexValidateUtils.getRandom10();
        HashMap<String, Object> map = new HashMap();
        map.put("countId", countId);
        map.put("userId", sp.getString("userId", ""));
        RetrofitManager.getInstance(AppConfig.BASE_URL).createReq(RequestApi.class).AddShareCount(map, RegexValidateUtils.getUniquePsuedoID(), timesamp, numsamp, MD5Utils.getMD5(RegexValidateUtils.ASCIISort(timesamp + numsamp + RegexValidateUtils.getUniquePsuedoID() + sp.getString("SignToken", "") + "countId" + countId + "userId" + sp.getString("userId", ""))).toUpperCase()).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<JSONObject>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
            }

            @Override
            public void onNext(JSONObject obj) {

            }
        });
    }

    public void GetJDdetail() {
        if (!DeviceUtils.isNetworkAvalible(mActivity)) {
            if (!mActivity.isFinishing()) {
                ToastUtils.getInstance(mActivity).showMessage("网络连接错误请检查");
            }
            return;
        }
        String timesamp = RegexValidateUtils.getTime13();
        String numsamp = RegexValidateUtils.getRandom10();
        HashMap<String, Object> map = new HashMap();
        map.put("skuIds", itemId);
        RetrofitManager.getInstance(AppConfig.BASE_URL).createReq(RequestApi.class).GetJDCategory(map, RegexValidateUtils.getUniquePsuedoID(), timesamp, numsamp, MD5Utils.getMD5(RegexValidateUtils.ASCIISort(timesamp + numsamp + RegexValidateUtils.getUniquePsuedoID() + sp.getString("SignToken", "") + "skuIds" + itemId)).toUpperCase()).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<JDBean>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
            }

            @Override
            public void onNext(JDBean bean) {
                if (bean.getCode() == 0) {
                    if (null == bean.getData()) {
                        commomDialog("该优惠券已被抢光");
                        return;
                    }
                    itemId = bean.getData().get(0).getSkuId();
                    String materialUrl = "https://wqitem.jd.com/item/view?sku=" + itemId;
                    String couponUrl = bean.getData().get(0).getCouponInfo().getCouponList().size() > 0 ? bean.getData().get(0).getCouponInfo().getCouponList().get(0).getLink() : "";
                    GetURL(materialUrl, couponUrl);
                    for (int i = 0; i < bean.getData().get(0).getImageInfo().getImageList().size(); i++) {
                        list.add(bean.getData().get(0).getImageInfo().getImageList().get(i).getUrl());
                    }
                } else if (bean.getCode() == -1) {
                    commomDialog("该优惠券已被抢光");
                }
            }
        });
    }

    public void GetURL(String materialUrl, String couponUrl) {
        if (!DeviceUtils.isNetworkAvalible(mActivity)) {
            if (!mActivity.isFinishing()) {
                ToastUtils.getInstance(mActivity).showMessage("网络连接错误请检查");
            }
            return;
        }
        String timesamp = RegexValidateUtils.getTime13();
        String numsamp = RegexValidateUtils.getRandom10();
        HashMap<String, Object> map = new HashMap();
        map.put("subUnionId", sp.getString("userId", ""));
        map.put("materialId", materialUrl);
        map.put("couponUrl", couponUrl);
        RetrofitManager.getInstance(AppConfig.BASE_URL).createReq(RequestApi.class).Bysubunionid(map, RegexValidateUtils.getUniquePsuedoID(), timesamp, numsamp, MD5Utils.getMD5(RegexValidateUtils.ASCIISort(timesamp + numsamp + RegexValidateUtils.getUniquePsuedoID() + sp.getString("SignToken", "") + "subUnionId" + sp.getString("userId", "") + "materialId" + materialUrl + "couponUrl" + couponUrl)).toUpperCase()).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<JSONObject>() {
            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable e) {
            }

            @Override
            public void onNext(JSONObject obj) {
                if (obj.getString("code").equals("0")) {
                    String quanurl = obj.getString("data");
                    cm.setPrimaryClip(ClipData.newPlainText(null, ""));
                    cm.setPrimaryClip(ClipData.newPlainText(null, "点击下面的链接即可领券" + "\n" + quanurl));
                    ToastUtils.getInstance(mActivity).showMessage("口令复制成功");
                }
            }
        });
    }

    public void GetPDDdetail() {
        String timesamp = RegexValidateUtils.getTime13();
        String numsamp = RegexValidateUtils.getRandom10();
        RetrofitManager.getInstance(AppConfig.BASE_URL).createReq(RequestApi.class).GetPromotion(itemId, sp.getString("userPhone", ""), RegexValidateUtils.getUniquePsuedoID(), timesamp, numsamp, MD5Utils.getMD5(RegexValidateUtils.ASCIISort(timesamp + numsamp + RegexValidateUtils.getUniquePsuedoID() + sp.getString("SignToken", "") + "UserPhone" + sp.getString("userPhone", "") + "Goodsid" + itemId)).toUpperCase()).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Subscriber<PddlinkBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(PddlinkBean bean) {
                if (bean.getCode().equals("0")) {
                    String shareUrl = bean.getData().get(0).getWe_app_web_view_short_url();
                    cm.setPrimaryClip(ClipData.newPlainText(null, ""));
                    cm.setPrimaryClip(ClipData.newPlainText(null, "点击下面的链接即可领券" + "\n" + shareUrl));
                    ToastUtils.getInstance(mActivity).showMessage("口令复制成功");
                }
            }
        });
    }

    public void commomDialog(String Message) {
        new CommonDialog.Builder(mActivity)
                .setTitle("提示")
                .setMessage(Message)
                .setMessageGravity()
                .setCanceledOnTouchOutside(false)
                .setPositiveButton("ok", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                    }
                }).show();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (null != shareBitmap && !shareBitmap.isRecycled()) {
            shareBitmap.recycle();
            shareBitmap = null;
            System.gc();
        }
        if (null != dataList) {
            dataList.clear();
            dataList = null;
        }
        if (null != shareList) {
            shareList.clear();
            shareList = null;
        }
        if (null != list) {
            list.clear();
            list = null;
        }
        if (null != mShareDialog && mShareDialog.isShowing()) {
            mShareDialog.cancel();
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.all: {
                shopFrom = "0";
                page = 1;
                GetCommunity();
                all.setChecked(true);
                tb.setChecked(false);
                pdd.setChecked(false);
                jd.setChecked(false);
            }
            break;
            case R.id.tb: {
                shopFrom = "1";
                page = 1;
                GetCommunity();
                all.setChecked(false);
                tb.setChecked(true);
                pdd.setChecked(false);
                jd.setChecked(false);
            }
            break;
            case R.id.jd: {
                shopFrom = "2";
                page = 1;
                GetCommunity();
                all.setChecked(false);
                tb.setChecked(false);
                jd.setChecked(true);
                pdd.setChecked(false);
            }
            break;
            case R.id.pdd: {
                shopFrom = "3";
                page = 1;
                GetCommunity();
                all.setChecked(false);
                tb.setChecked(false);
                jd.setChecked(false);
                pdd.setChecked(true);
            }
            break;
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }
}
